import Vue from 'vue'
import Router from 'vue-router'
import Tab from '@/components/order/Tab'
import Apply from '@/components/apply/Apply'
import My from '@/components/my/My'
import UserInfo from '@/components/my/UserInfo'
import Count from '@/components/my/Count'

import axios from 'axios'
Vue.use(Router)
const router = new Router({
    routes: [{
        path: '/tab',
        name: 'tab',
        component: Tab
    }, {
        path: '/apply',
        name: 'apply',
        component: Apply
    }, {
        path: '/my',
        name: 'my',
        component: My
    }, {
        path: '/count',
        name: 'count',
        component: Count
    }, {
        path: '/user',
        name: 'user',
        component: UserInfo
    }]
})

router.beforeEach(function (to, from, next) {
    // const nextRoute = [ 'tab', 'apply', 'my', 'count', 'user']
    let toUrl = ''
    if (to.name === 'apply') {
        toUrl = '0'
    } else if (to.name === 'list') {
        toUrl = '1'
    } else {
        toUrl = '2'
    }
    axios
    .get('/api/expressUser/isLogin', {
        params: {
            toUrl: toUrl
        }
    })
    .then(res => {
        console.log(res)
        window.location.href = res.data.authUrl
        // window.location.href('http://www.baidu.com')
    })
    .catch(err => {
        console.log(err)
    })
    // //跳转至上述3个页面
    // if (nextRoute.indexOf(to.name) >= 0) {
    //     //未登录
    //     if (!store.state.auth.IsLogin) {
    //         vueRouter.push({name: 'login'})
    //     }
    // }
    // //已登录的情况再去登录页，跳转至首页
    // if (to.name === 'login') {
    //     if (auth.IsLogin) {
    //         vueRouter.push({name: 'home'});
    //     }
    // }
    // next();
    console.log(to)
    console.log(from)
    console.log(next)
})
export default router
